home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / comm / tlx_sq15.zip / MARKMAIL.SLT < prev    next >
Text File  |  1991-02-08  |  12KB  |  357 lines

  1. //-----------------------------------------------------------
  2. // MarkMail.SL?   Telix script to fetch mail from a PCBoard BBS.
  3. //
  4. // This script is normally called from the script PCBOARD.SLC.
  5. //
  6. // Please look at the comments through the whole file, and modify to
  7. // suit your needs, BEFORE you use it. Then recompile with CS MarkMail.
  8. //-----------------------------------------------------------
  9.  
  10. // This script is assumed to be called ONLY after logon
  11. // to perform routine tasks. This is done from the LOGON
  12. // script, and the system can ONLY be PCBOARD. Also,
  13. // we MUST be online in order to arrive here, and the
  14. // TELIX main directory must be the current one.
  15. // Therefore, system and online checks are simply skipped.
  16.  
  17. str codename [12]                        // BBS code/filename
  18.    ,myprot    [2]                        // My protocol
  19.    ,help     [80]                        // Help line.
  20.    ,runstr   [80]                        // DSZ runstring (if used).
  21.    ,downdir  [64]                        // Save of download directory.
  22.                                          // Script and global names:
  23.    ,global     []="GLOBAL"               // Global script.
  24.    ,Cprot      []="CPROT"                // Current protocol.
  25.    ,Cname      []="CNAME"                // Codename of current BBS.
  26.    ,prompt     []="PROMPT"               // Current command prompt.
  27.    ,mdir       []="MDIR"                 // Mail directory.
  28.    ,dsz        []="DSZ"                  // Code for DSZ (if in use).
  29.    ;     
  30.  
  31. int tol = 300                            // No activity for 30 sec.
  32.    ,tmark                                // makes script time out. 
  33.    ,stat                                 // For tracking.
  34.    ;                           
  35.  
  36. //-----------------------------------------------------------
  37. // MarkMail script is entered here.                                   
  38. //-----------------------------------------------------------
  39.  
  40. main()
  41. {
  42. int c
  43.    ,i
  44.    ,l
  45.    ,na
  46.    ,save
  47.    ,MailOK
  48.    ,error                                // Error ind.      
  49.    ,com                                  // command
  50.    ,pnm                                  // Packet name
  51.    ,stf                                  // Start transfer
  52.    ,don                                  // [G]oodbye When Done?
  53.    ;
  54.  
  55.   entry();                               // Updates status bar.
  56.   newdir (_telix_dir);                   // Must be in TELIX main directory!
  57.   read (cprot,myprot);                   // Get current BBS protocol.
  58.  
  59.   pnm = 0;
  60.   if (read(cname,Codename) < 0)          // If codename is unknown,
  61.     pnm = track ("ket Name: ",0);        // Get packet name.
  62.   com = track (" Command?",0);           // Command.
  63.   stf = track ("s Transfer",0);          // Start tracking this now.
  64.  
  65.   tmark = timer_start (tol);             // Give me a minute.
  66.  
  67.   while ((stat=trig()) > 0)              // answer any questions.
  68.   { if (stat == com)
  69.       cputs ("U^M");                     // Start upload.
  70.  
  71.     else if (stat == pnm)                // Packet name?
  72.     { waitfor ("^J",1);                  // Wait for linefeed.
  73.       for (l=gety()-1; l>=0; --l)        // Get previous line.
  74.       { vgetchrs(0,l,help,0,80);
  75.         if ((i=strposi (help,"ket Name: ",0)) > 0) // Packet name?
  76.         { i = i+10;
  77.           na = 0;
  78.           while ((c=subchr(help,i)) != '.') // All before decimal point:
  79.           { setchr(codename,na,c);
  80.             if (++na >= 12) break;
  81.           }
  82.           setchr (codename,na,0);        // End the string.
  83.           write (cname,codename);        // Save BBS ID-code.
  84.           break;                         // Break out of (inner) loop.
  85.         }
  86.       }
  87.     }
  88.     else if (stat==stf)                  // Start transfer
  89.       break;
  90.   }
  91.   release();                             // Release tracks.
  92.   if (stat < 0) goto done;               // Time-out or carrier lost.
  93.  
  94. // Start sending the mail packet.
  95.  
  96.   help = _up_dir;                        // Get upload dir.
  97.   strcat (help,codename);                // Add name.
  98.   strcat (help,".REP");                  // Add extension.
  99.  
  100.   if (filesize(help) <= 0)               // No file to send?
  101.   { release();
  102.     MarkAbort();                         // Abort transfer.
  103.   }
  104.   else
  105.   { send_file ();                        // Send it.
  106.     fdelete (help);                      // Remove the mail file.
  107.   }
  108.  
  109. // Start download.
  110. //-----------------------------------------------------------
  111.  
  112.   save = _zmod_auto;
  113.   MailOK = _zmod_auto = 0;               // Disable Zmodem-auto.  
  114.   downdir = _down_dir;
  115.   read (mdir,_down_dir);                 // D/L to this directory.
  116.  
  117. // Define strings for tracking.
  118. //-----------------------------------------------------------
  119.  
  120.   stf = track ("s Transfer",0);          // Start transfer.
  121.   com = track (" Command?",0);           // Back to command.
  122.   pnm = track ("No Message",0);          // No messages.
  123.   don = track ("When Done?",0);          // Wanna receive?
  124.  
  125.   track ("...",0);                       // Still searching.
  126.   track ("      ",0);                    // Still searching.
  127.  
  128.   cputs ("D^M");                         // Download now.
  129.  
  130.   tmark = timer_start (tol);             // Give me a minute.
  131.   error = 1;
  132.   while ((stat=trig()) > 0)              // answer any questions.
  133.   { if (stat == stf)                     // Download now?
  134.     { error = get_file();
  135.       _down_dir = downdir;               // Restore download dir.
  136.     }
  137.     else if (stat==pnm)
  138.       error = 0;                         // No messages. Simulate "done".
  139.  
  140.     else if (stat==don)                  // Wanna receive now?
  141.       cputs ("y^M");
  142.  
  143.     else if (stat==com)
  144.     { if (MailOK) 
  145.         break;                           // MailOK is used to
  146.       cputs ("qu^M");                    // indicate if we have
  147.       MailOK = 1;                        // returned to PCBoard.
  148.     }
  149.   }
  150. done:
  151.   release();                             // Free all tracks and timer.
  152.   if (stat < 0) failtone();
  153.   _zmod_auto = save;
  154.   _down_dir = downdir;                   // Restore download dir.
  155.  
  156.   return (error);
  157. }
  158.  
  159. //-----------------------------------------------------------
  160. // Routine to update colors and status bar.
  161. //-----------------------------------------------------------
  162.  
  163. entry ()
  164. {
  165.   _back_color = 1;
  166.   _fore_color = 14;
  167.   update_term();
  168. }
  169.  
  170. //-----------------------------------------------------------
  171. // Play fail tone.
  172. //-----------------------------------------------------------
  173.  
  174. failtone()
  175. {
  176.   int n;
  177.   for (n=140; n > 10; n = 100*n/120) 
  178.   { tone(n*10,12);                       // Fail tone!!
  179.     terminal();                          // Process text.
  180.   }
  181. }
  182.  
  183. //-----------------------------------------------------------
  184. // Play good tune.
  185. //-----------------------------------------------------------
  186.  
  187. goodtone()
  188. {
  189. int n;
  190.   for (n=20; n < 200; n = 144*n/100) 
  191.   { tone(n*10,6);                        // Good tone!
  192.     terminal();                          // Process text.
  193.   }
  194. }
  195.  
  196. //-----------------------------------------------------------
  197. // Free timer and tracking functions.
  198. //-----------------------------------------------------------
  199.  
  200. release()
  201. {
  202.   timer_free (tmark);                    // free timer channel
  203.   track_free (0);                        // and all track channels.
  204. }
  205.  
  206. //-----------------------------------------------------------
  207. //  Trig loop. Waits here until either one "trig string" is
  208. //  found, or we have a time-out, or carrier is lost.
  209. //-----------------------------------------------------------
  210.  
  211. trig()
  212. {
  213. int i;
  214.   do
  215.   { terminal();
  216.   }  while (!time_up (tmark)             // Loop until time-out
  217.           && carrier()                   // or carrier lost
  218.           && (i=track_hit(0))==0);       // or we trigged.
  219.   if (i==0) 
  220.     i = -1;                              // Error!
  221.   else
  222.     timer_restart (tmark,tol);           // Restore timer.
  223.   return (i);
  224. }
  225.  
  226. //----------------------------------------------------------
  227. // Abort MarkMail door.
  228. //-----------